package com.yjx.managedemo.controller;

import com.yjx.managedemo.entity.Employees;
import com.yjx.managedemo.mapper.EmployeesDao;
import com.yjx.managedemo.po.EmployeesQuery;
import com.yjx.managedemo.re.PageResult;
import com.yjx.managedemo.re.Result;
import com.yjx.managedemo.service.EmployeesService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("employees")
public class EmployeesController {
    @Resource
    private EmployeesService employeesService;

    @RequestMapping("toIndexEmployees")
    public  String toIndexEmployees(){
        return "index_employees";
    }

    @RequestMapping("toEmployeesList")
    public  String toEmployeesList(){
        return "employees_list";
    }

    @RequestMapping("queryByAllLimit")
    @ResponseBody
    public PageResult emplist(EmployeesQuery employeesQuery){

        return employeesService.queryAllEmployees(employeesQuery);
    }

    @RequestMapping("toEmployeesAdd")
    public  String toEmployeesAdd(){
        return "employees_add";
    }


    @RequestMapping("add")
    @ResponseBody
    public Result insert(Employees employees){
        if (employees.getName() == null || employees.getName().equals("")) {
            return Result.fail();
        }else if(employees.getPassword() == null || employees.getPassword().equals("")){
            return Result.fail();
        }else if(employees.getEmail() == null || employees.getEmail().equals("")){
            return Result.fail();
        }else if(employees.getPhone() == null || employees.getPhone().equals("")){
            return Result.fail();
        }
        return Result.success(employeesService.insert(employees));
    }

    @RequestMapping("toEmployeesUpdate")
    public  String toEmployeesUpdate(){
        return "employees_update";
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(Employees employees){
        if (employees.getName() == null || employees.getName().equals("")) {
            return Result.fail();
        }else if(employees.getPassword() == null || employees.getPassword().equals("")){
            return Result.fail();
        }else if(employees.getEmail() == null || employees.getEmail().equals("")){
            return Result.fail();
        }else if(employees.getPhone() == null || employees.getPhone().equals("")){
            return Result.fail();
        }
        return Result.success(employeesService.update(employees));
    }

    @RequestMapping("queryById")
    @ResponseBody
    public Result<String> queryById(Integer employeeId){
        return Result.success(employeesService.queryById(employeeId));
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result delete(Integer employeeId){
        return Result.success(employeesService.deleteById(employeeId));
    }
}


